// pages/attention/attention.js
Page({
    /**
     * 页面的初始数据
     */
    data: {
        index: 0,
        SharedFlatsTopic: [],
        AskingForRentTopic: [],
        userId: parseInt(wx.getStorageSync('userInfo').userId, 10), // 转换为整数类型,
        moreHouseSourse: [],
    },
    //绑定数据
    changeIndex(event) { //event事件对象
        // console.log(event.target.dataset.index)
        this.setData({
            index: event.target.dataset.index
        })
        if (event.target.dataset.index === '2') {
            this.getSharedFlatsList()
        } else if (event.target.dataset.index === '1') {
            this.getAskingForRentList()
        }
    },

    getAskingForRentList() {
        wx.request({
            url: 'http://localhost:8080/ihome/topic/selectaskingforrent',
            method: "GET",
            data: {
                userId: 1
            },
            success: (resp) => {
                console.log(resp)
                this.setData({
                    AskingForRentTopic: resp.data.data
                })
            }
        })
    },
    getSharedFlatsList() {
        wx.request({
            url: 'http://localhost:8080/ihome/topic/selectsharedflats',
            method: "GET",
            data: {
                userId: 1
            },
            success: (resp) => {
                console.log(resp)
                this.setData({
                    SharedFlatsTopic: resp.data.data
                })
            }
        })
    },    getUserInfo() {
        var value = wx.getStorageSync('userInfo')
        this.setData({
            userId: value.userId
        })
    },
    //更多房源
    getMoreHouseSourse() {
        wx.request({
            url: 'http://localhost:8080/ihome/collect/list',
            header: {
                'Authorization': 'Bearer ' + wx.getStorageSync('token')
            },
            data: {
                // lessor: 1,
                userId:1,
                collectType:0,
                // houseIdOrTopicId:this.data.houseId,
                // pageNum: 1,
                // pageSize: 3
            },
            success: (resp => {
                console.log(resp.data)
                this.setData({
                    moreHouseSourse: resp.data.rows
                })
            })
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.getUserInfo()
        if (wx.getStorageSync('token') == '' || wx.getStorageSync('token') == null || wx.getStorageSync('token') == undefined) {
            wx.redirectTo({
                url: '/pages/my/login/login',
            })
            return;
        }
        this.getMoreHouseSourse();
        // this.setData({
        //   houseId: options.id,
        //   // userId: options.userId
        // })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
      this.getMoreHouseSourse();
      this.getSharedFlatsList();
      this.getAskingForRentList();
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})